package com.mcb_wxc.util;

import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Slf4j
public class ReturnJsonResultUtil {
    //返回状态结果码0失败1成功2未登录3权限不够
    private String resultCode = CodeUtil.SUCCESS;
    //错误描述
    private String content = "";
    //要跳转的url
    private String urlPath = "";
    //返回的数据
    private Object mainData = "";

    public void setResultCode(String resultCode) {
        this.resultCode = resultCode;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void setUrlPath(String urlPath) {
        this.urlPath = urlPath;
    }

    public void setMainData(Object mainData) {
        this.mainData = mainData;
    }
    public String toString() {
        Gson gson = new Gson();
        return gson.toJson(this);
    }

    /**
     * 打印错误信息
     * @param request
     * @param e
     */
    public void printLog(HttpServletRequest request, Exception e) {
        log.info("-----------------分割线-----------------");
        log.error("logger：\n" +
                "时间:{}\n请求URL:{}\n 参数:{}\n异常描述：{}", DateFormatUtil.formatDateForSec(new Date()), request.getRequestURI(), request.getQueryString(), e.getMessage());
        log.info("-----------------分割线-----------------");
    }
}
